package com.example.esp32;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;


public class ztlistAdapter extends BaseAdapter {

    private Context mContext;
    private List<getValue> mList = new ArrayList<getValue>();

    static class ViewHolder {
        TextView sbmc,dyzt,ip;
        ImageView tupian;
    }

    public ztlistAdapter(Context context, List<getValue> list) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }



    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder = null;
        //初始化卡片样式
        if (view == null) {
            viewHolder = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.activity_listxml, null);
//            viewHolder.tupian = view.findViewById(R.id.img);
//            viewHolder.bianji = view.findViewById(R.id.bianji);
            viewHolder.sbmc = view.findViewById(R.id.mc);
            viewHolder.dyzt = view.findViewById(R.id.zt);
            viewHolder.ip = view.findViewById(R.id.ip);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

//        viewHolder.tupian.setImageResource(mList.get(i).getTupian());
        viewHolder.sbmc.setText(mList.get(i).getsbmc());
        viewHolder.dyzt.setText(mList.get(i).getdyzt());
        viewHolder.ip.setText(mList.get(i).getip());
//        viewHolder.bianji.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                mOnItemUpdateListener.onUpdateClick(i);
//            }
//        });

return view;
    }
//    public interface onItemUpdateListener {
//        void onUpdateClick(int i);
//    }
//
//    private onItemUpdateListener mOnItemUpdateListener;
//
//    public void setOnItemUpdateClickListener(onItemUpdateListener mOnItemUpdateListener) {
//        this.mOnItemUpdateListener = mOnItemUpdateListener;
//    }

    public void clear() {

            if (mList != null) {
                mList.clear();
            } else {
                mList.clear();
            }

}}